package com.industrial.white.controller;


import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.white.domain.EmDataSubmission;
import com.industrial.white.service.IEmDataSubmissionService;
import com.industrial.white.vo.EmDataSubmissionMounthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据报送Controller
 * 
 * @author Zhou_S
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/dataSubmission")
public class EmDataSubmissionController extends BaseController
{
    @Autowired
    private IEmDataSubmissionService emDataSubmissionService;

    @GetMapping("/groupList")
    public TableDataInfo groupList(EmDataSubmission emDataSubmission)
    {

        startPage();
        List<EmDataSubmissionMounthVo> list = emDataSubmissionService.groupList(emDataSubmission);
        return getDataTable(list);
    }
    /**
     * 查询数据报送列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EmDataSubmission emDataSubmission)
    {
        List<EmDataSubmission> list = emDataSubmissionService.selectEmDataSubmissionList(emDataSubmission);
        return getDataTable(list);
    }

    /**
     * 导出数据报送列表
     */
    @Log(title = "数据报送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmDataSubmission emDataSubmission)
    {
        List<EmDataSubmission> list = emDataSubmissionService.selectEmDataSubmissionList(emDataSubmission);
        ExcelUtil<EmDataSubmission> util = new ExcelUtil<EmDataSubmission>(EmDataSubmission.class);
        util.exportExcel(response, list, "数据报送数据");
    }

    /**
     * 获取数据报送详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(emDataSubmissionService.selectEmDataSubmissionByBaseId(baseId));
    }

    /**
     * 新增数据报送
     */
    @Log(title = "数据报送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmDataSubmission emDataSubmission)
    {

       int flag= emDataSubmissionService.insertEmDataSubmission(emDataSubmission);
        if(flag>0){
            return AjaxResult.success("添加成功!");
        }else{
            return AjaxResult.warn("本月数据已上报！");
        }

    }

    /**
     * 修改数据报送
     */
    @Log(title = "数据报送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmDataSubmission emDataSubmission)
    {
        return toAjax(emDataSubmissionService.updateEmDataSubmission(emDataSubmission));
    }

    @Log(title = "数据报送", businessType = BusinessType.UPDATE)
    @PutMapping("editUpdateIds")
    public AjaxResult editUpdateIds(@RequestBody EmDataSubmission[] emDataSubmissions)
    {
    if(emDataSubmissions.length>0){
        return toAjax(emDataSubmissionService.updateByBaseIds(emDataSubmissions));
    }else{
        return AjaxResult.warn("无此操作权限！");
    }
    }

    /**
     * 删除数据报送
     */
    @Log(title = "数据报送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(emDataSubmissionService.deleteEmDataSubmissionByBaseIds(baseIds));
    }

}
